import NProgress from 'nprogress'

/**
 * 页面头部加载条
 * @param duration 持续时间ms, 默认200ms
 * @param excute 执行方法
 */
export const pageHeaderSpin = (duration = 200, excute?: () => any) => {
  NProgress.start()
  return new Promise(async (resolve, reject) => {
    if (excute) {
      try {
        await excute()
      } catch (e) {
        return reject()
      }
    }
    setTimeout(() => {
      NProgress.done()
      resolve(1)
    }, duration)
  })
}